#include "CTNLinkStack.h"

void cTNLinkStack::push(cLinkTreeNode* e)
{
	cTNLinkNode* p = new cTNLinkNode(e, this->head->next);
	this->head->next = p;
}

cLinkTreeNode* cTNLinkStack::pop()
{
	if (this->isEmpty())
	{
		return NULL;
	}
	cLinkTreeNode* c;
	c = this->head->next->data;
	cTNLinkNode* p = this->head->next;
	this->head->next = p->next;
	delete p;
	return c;
}

bool cTNLinkStack::isEmpty()
{
	if (this->head->next==nullptr)
	{
		return true;
	}
	else
	{
		return false;
	}
}

cLinkTreeNode* cTNLinkStack::getTop()
{
	return this->head->next->data;
}

cTNLinkStack::cTNLinkStack()
{
	this->head = new cTNLinkNode();
}

cTNLinkStack::~cTNLinkStack()
{
	cTNLinkNode* p, * pre;
	p = this->head;
	pre = p->next;
	while (pre!=nullptr)
	{
		delete p;
		p = pre;
		pre = pre->next;
	}
	delete p;
}